package two;

public class DivideExpression extends AbstractExpression {
    public DivideExpression(int num1, int num2) {
        super(num1, num2);
        if (num2 == 0) throw new IllegalArgumentException("除数不能为0");
    }

    @Override
    public int calculate() {
        int max = Math.max(num1, num2);
        int min = Math.min(num1, num2);
        if (max % min != 0) throw new IllegalArgumentException("无法整除");
        return max / min;
    }

    @Override
    public String toString() {
        int max = Math.max(num1, num2);
        int min = Math.min(num1, num2);
        return max + " / " + min + " = " + result;
    }
}
